package com.yzq.controller;

import com.yzq.common.Result;
import com.yzq.enums.ErrorCode;
import com.yzq.model.dto.space.analyze.*;
import com.yzq.model.entity.Space;
import com.yzq.model.vo.spaceAnalyze.*;
import com.yzq.service.SpaceAnalyzeService;
import com.yzq.utils.ThrowUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Slf4j
@Api(tags = "空间分析接口")
@RestController
@RequestMapping("/space/analyze")
public class SpaceAnalyzeController {
    @Resource
    private SpaceAnalyzeService spaceAnalyzeService;


    @ApiOperation("获取空间使用状态")
    @PostMapping("/usage")
    public Result<SpaceUsageAnalyzeResponse> getSpaceUsageAnalyze(
            @RequestBody SpaceUsageAnalyzeRequest spaceUsageAnalyzeRequest,
            HttpServletRequest request) {
        ThrowUtils.throwIf(spaceUsageAnalyzeRequest == null, ErrorCode.BAD_REQUEST);
        log.info("获取空间使用状态: {}", spaceUsageAnalyzeRequest);
        SpaceUsageAnalyzeResponse spaceUsageAnalyze = spaceAnalyzeService.getSpaceUsageAnalyze(spaceUsageAnalyzeRequest, request);
        return Result.success(spaceUsageAnalyze);
    }


    @ApiOperation("获取空间图片分类分析")
    @PostMapping("/classify")
    public Result<List<SpaceClassifyAnalyzeResponse>> getSpaceCategoryAnalyze(
            @RequestBody SpaceClassifyAnalyzeRequest spaceClassifyAnalyzeRequest,
            HttpServletRequest request) {
        ThrowUtils.throwIf(spaceClassifyAnalyzeRequest == null, ErrorCode.BAD_REQUEST);
        log.info("获取空间图片分类分析: {}", spaceClassifyAnalyzeRequest);
        List<SpaceClassifyAnalyzeResponse> spaceCategoryAnalyze = spaceAnalyzeService.getSpaceCategoryAnalyze(spaceClassifyAnalyzeRequest, request);
        return Result.success(spaceCategoryAnalyze);
    }


    @ApiOperation("获取空间图片标签分析")
    @PostMapping("/tag")
    public Result<List<SpaceTagAnalyzeResponse>> getSpaceTagAnalyze(
            @RequestBody SpaceTagAnalyzeRequest spaceTagAnalyzeRequest,
            HttpServletRequest request) {
        ThrowUtils.throwIf(spaceTagAnalyzeRequest == null, ErrorCode.BAD_REQUEST);
        log.info("获取空间图片标签分析: {}", spaceTagAnalyzeRequest);
        List<SpaceTagAnalyzeResponse> spaceTagAnalyze = spaceAnalyzeService.getSpaceTagAnalyze(spaceTagAnalyzeRequest, request);
        return Result.success(spaceTagAnalyze);
    }


    @ApiOperation("获取空间图片大小分析")
    @PostMapping("/size")
    public Result<List<SpaceSizeAnalyzeResponse>> getSpaceSizeAnalyze(@RequestBody SpaceSizeAnalyzeRequest spaceSizeAnalyzeRequest,
                                                                            HttpServletRequest request) {
        ThrowUtils.throwIf(spaceSizeAnalyzeRequest == null, ErrorCode.BAD_REQUEST);
        log.info("获取空间图片大小分析: {}", spaceSizeAnalyzeRequest);
        List<SpaceSizeAnalyzeResponse> resultList = spaceAnalyzeService.getSpaceSizeAnalyze(spaceSizeAnalyzeRequest, request);
        return Result.success(resultList);
    }


    @ApiOperation("获取空间用户行为分析")
    @PostMapping("/user")
    public Result<List<SpaceUserAnalyzeResponse>> getSpaceUserAnalyze(@RequestBody SpaceUserAnalyzeRequest spaceUserAnalyzeRequest,
                                                                            HttpServletRequest request) {
        ThrowUtils.throwIf(spaceUserAnalyzeRequest == null, ErrorCode.BAD_REQUEST);
        log.info("获取空间用户行为分析: {}", spaceUserAnalyzeRequest);
        List<SpaceUserAnalyzeResponse> resultList = spaceAnalyzeService.getSpaceUserAnalyze(spaceUserAnalyzeRequest, request);
        return Result.success(resultList);
    }



    @ApiOperation("获取空间使用排行分析")
    @PostMapping("/rank")
    public Result<List<Space>> getSpaceRankAnalyze(@RequestBody SpaceRankAnalyzeRequest spaceRankAnalyzeRequest,
                                                         HttpServletRequest request) {
        ThrowUtils.throwIf(spaceRankAnalyzeRequest == null, ErrorCode.BAD_REQUEST);
        log.info("获取空间使用排行分析: {}", spaceRankAnalyzeRequest);
        List<Space> resultList = spaceAnalyzeService.getSpaceRankAnalyze(spaceRankAnalyzeRequest, request);
        return Result.success(resultList);
    }
}
